package top.lilele.adminSystem.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;
import top.lilele.adminSystem.validGroup.AddUserGroup;
import top.lilele.adminSystem.validGroup.UpdateUserGroup;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;


/**
 * @author lilele
 */
@Data
@TableName(value = "admin_user")
public class AdminUserEntity implements Serializable {
    /**
     * id
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;

    /**
     * 用户名
     */
    @NotEmpty(message = "账号不能为空", groups = {AddUserGroup.class, UpdateUserGroup.class})
    @Length(max = 30, message = "账号1-30位", groups = {AddUserGroup.class, UpdateUserGroup.class})
    @TableField(value = "username")
    private String username;
    /**
     * 密码
     */
    @NotEmpty(message = "密码不能为空", groups = {AddUserGroup.class})
    @TableField(value = "password")
    private String password;

    /**
     * 用户名
     */
    @NotEmpty(message = "用户名不能为空", groups = {AddUserGroup.class, UpdateUserGroup.class})
    @Length(max = 30, message = "用户名1-30位", groups = {AddUserGroup.class, UpdateUserGroup.class})
    @TableField(value = "trueName")
    private String trueName;
    /**
     * 头像
     */
    @TableField(value = "picture")
    private String picture;
    /**
     * 手机号
     */
    @NotEmpty(message = "手机号不能为空", groups = {AddUserGroup.class, UpdateUserGroup.class})
    @Pattern(regexp = "^[1][1,2,3,4,5,7,8,9][0-9]{9}$", message = "手机号格式不正确", groups = {AddUserGroup.class, UpdateUserGroup.class})
    private String phone;
    /**
     * 邮箱
     */
    @NotEmpty(message = "邮箱不能为空", groups = {AddUserGroup.class, UpdateUserGroup.class})
    @Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+", message = "邮箱格式不正确", groups = {AddUserGroup.class, UpdateUserGroup.class})
    private String email;
    /**
     * 地址
     */
    private String location;

    /**
     * 性别
     */
    @NotNull(message = "性别不能为空", groups = {AddUserGroup.class, UpdateUserGroup.class})
    private Integer sex;

    /**
     * 账号状态： 1 可用 ；2 不可用
     */
    @TableField(value = "available")
    private Integer available;

    /**
     * 是否是系统管理员 1 是 2 不是
     */
    @TableField(value = "isAdmin")
    private Integer isAdmin;

    /**
     * 入职时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @NotNull(message = "入职时间不能为空", groups = {AddUserGroup.class, UpdateUserGroup.class})
    @TableField(value = "inductionTime")
    private Date inductionTime;


    @TableField(value = "createdTime", fill = FieldFill.INSERT)
    private Date createdTime;
    @TableField(value = "updatedTime", fill = FieldFill.UPDATE)
    private Date updatedTime;
}
